<template>
	<view class="content" >
		<view class="" :style="{ width: bodyWidth + 'px',height: bodyHeight + 'px' }">
			<image src="../../static/images/work1.jpg" mode="" class="img_bg" :style="{ height: bodyHeight + 'px' }"></image>
			 <!-- #ifdef MP-WEIXIN -->
				 <uni-notice-bar showIcon text="万基集团用户请点击此处到新小程序" @click="goToNewMP()" v-if="navigator_to == '00001'"></uni-notice-bar>
			  <!-- #endif -->
			
			<form @submit="formSubmit" @reset="formReset">
				<view class="indexBg">智慧云安全管理系统</view>

				<view class="">
					<view class="loginInput bgc " style="background-color: transparent; border-bottom: solid 1upx #F1F1F1;">
						<image src="/static/name.png" mode="widthFix" class="loginImg"></image>
						<input v-model="logUser" type="text" class="search-input  bgc " placeholder-style="color:#999;font-size:32upx;"
						 placeholder="请输入用户名" @confirm="searchHouse" name="account" style="background-color: transparent;" />
					</view>
					<view class="loginInput bgc" style="background-color: transparent; border-bottom: solid 1upx #F1F1F1;">
						<image src="/static/password.png" mode="widthFix" class="loginImg"></image>
						<input class="search-input " style="background-color: transparent;" name="password" v-model="logPass" type="text" placeholder="请输入密码" placeholder-style="color:#999;font-size:32upx;"
						 v-if="show_pass" />
						<input class="search-input " style="background-color: transparent;" name="password" v-model="logPass" password="true" placeholder="请输入密码"
						 placeholder-style="color:#999;font-size:32upx;" v-else key="passw-input" />
						<view class="yan-posi">
							<image src="/static/look.png" @tap="seeTap" class="loginImg" mode="widthFix" v-if="show_pass"></image>
							<image src="/static/nolook.png" @tap="seeTap" class="loginImg" mode="widthFix" v-else></image>
						</view>
					</view>
					<view class="margin-t20 text-right margin-r54">
						<checkbox-group @change="agree">
							<label>
								<checkbox value="ok" style="transform:scale(0.5)" color="#D9000F" :checked="ischecked" />
							</label>
							<view class="font-gray text-24 display-inline">记住密码</view>
						</checkbox-group>
					</view>
					<view class="bottom">
						<view class="">
							<view>
								<view class="ma" type="primary" @click="tel()">
									<view class="inf">
										查看风险点信息
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="margin-r54 margin-bottom margin-t30 margin-l54">
						<button class="loginButton" formType="submit" :disabled="disable_check">登 录</button>
					</view>

				</view>
			</form>
		</view>
			<!-- <uni-popup ref="popup" type="bottom" backgroundColor="#fff">
				<view class="" style="height: 500rpx;">
					<image src="" mode=""></image>
				</view>
			</uni-popup> -->
			
	</view>
</template>
<script>
	export default {
		data() {
			return {
				show_pass: false, //密码的显示隐藏
				inputType: "password",
				agreenAll: [],
				logPass: '',
				logUser: '',
				ischecked: false,
				disable_check: false,
				banben: '',
				type: 1,
				urrl: '',
				version: "1.0",
				bodyHeight:'',//固定页面高度
				bodyWidth:'',
				navigator_to:'00001'
			}
		},
		onShow() {
			//plus.runtime.setBadgeNumber(8);
		},
		mounted(){
		 
		},
		onLoad() {
			// yys为审批用账号
			if(uni.getStorageSync('user').nickname == 'yys'){
				this.navigator_to = '0';
			}
			this.bodyHeight=uni.getSystemInfoSync().windowHeight;// 把页面高度定成视口高度
			this.bodyWidth = uni.getSystemInfoSync().windowWidth;
			// console.log(this.bodyWidth)
			if (uni.getStorageSync("louser")) {
				this.logUser = uni.getStorageSync("louser").user;
				this.logPass = uni.getStorageSync("louser").pass;
				this.ischecked = false;
			}
		},
		methods: {
			//跳转到新小程序
			goToNewMP(){
				// this.$refs.popup.open();
				wx.navigateToMiniProgram({
				  appId: 'wx2d09ebc763efb5a7',
				  success(res) {
				    // 打开成功
				  },
				  fail: () => {
				  	uni.showToast({
				  		title:'跳转失败',
						icon:"none"
				  	})
				  }
				})
			},
			seeTap: function() {
				this.show_pass = !this.show_pass
				inputType: this.data.inputType === 'password' ? 'text' : 'password'
			},
			agree(e) {
				this.agreenAll = e.detail.value;
			},
			formSubmit(e) {
				var that = this
				// console.log(e)
				let parse = e.detail.value;
				if (uni.getStorageSync("openid")) {
					parse.openid = uni.getStorageSync("openid");
				} else {
					parse.openid = '';
				}
				if (parse.account == "") {
					uni.showToast({
						title: '用户名不能为空',
						icon: "none"
					});
					return false;
				} else if (parse.password == "") {
					uni.showToast({
						title: '密码不能为空',
						icon: "none"
					});
					return false;
				} else {
					if (this.agreenAll.length > 0) {
						let stroge = {
							user: parse.account,
							pass: parse.password
						}
						uni.setStorageSync("louser", stroge)
					}
					uni.request({
						url: 'https://aqmore.sxpz.vip/AppApi/Login/login',
						// url: 'https://wanji.shangdezhineng.com/Login/login',
						method: 'POST',
						header: {
							'content-type': 'application/x-www-form-urlencoded',
						},
						data: {
							username: this.logUser,
							password: this.logPass,
						},
						success: function(res) {
							that.disable_check = true
							// console.log(res)
							var parses = res.data.datas;
							// console.log(parses)
							if (res.data.code == 200) {
								uni.setStorageSync("user", res.data.datas);
								uni.showToast({
									title: '登陆成功',
									icon: 'success',
									duration: 1500
								})
								setTimeout(function() {
									uni.switchTab({
										url: '../workspace/workspace'
									})
								}, 1500)
							} else {
								uni.showToast({
									title: res.data.datas.msg,
									icon: 'none'
								})
								that.disable_check = false
							}
						},
					})
				}
			},
			tel: function() {
				var that = this
				uni.scanCode({
					success: function(res) {
						// console.log(JSON.stringify(res));
						// console.log('条码类型：' + res.scanType);
						// console.log('条码内容：' + res.result);
						let scene = res.result.split('=');
						// console.log(scene[0])
						let e1 = scene[0].split('?')
						// console.log(e1[0])
						let e = scene[1].split('&');
						let e2 = scene[1].split('?')[0].split('&');
						// console.log(e2)
						// console.log(e2[0])
						uni.request({
							url: 'https://aqmore.sxpz.vip/AppApi/Danger/detail?danger_id=' + e2[0],
							method: 'GET',
							header: {
								'content-type': 'application/x-www-form-urlencoded'
							},
							success: function(res) {
								// console.log(res)
								that.danger_status = res.data.datas.danger.danger_status
								// console.log(that.danger_status)
								if (that.danger_status == 1) {
									let button = true
									uni.navigateTo({
										url: '../workspace/workDetial/polling/polling?id=' + e[0]+'&rel='+button
									})
								} else if (that.danger_status == 3) {
									uni.showToast({
										title: '该二维码为设备设施二维码，请扫描风险点二维码',
										icon: 'none'
									})
								} else {
									uni.showToast({
										title: '请扫描正确的二维码',
										icon: 'none'
									})
									return
								}
							}
						})
					},
					fail: function() {
						uni.showToast({
							title: '请扫描二维码',
							icon: 'none'
						})
					}
				});
			}
		}
	}
</script>
<style>
	page {
		width: 100%;
		height: 100%;
		/* background-color: #03182b; */
	}
	form{
		background-color: $uni-bg-color;
		position: relative;
		width: 100%;
		display: flex;
		flex-direction: column;
	}
	.img_bg {
		width: 100%;
		height: 100%;
		position: fixed;
		background-size: 100% 100%;
		z-index: -1;

	}

	.ma {
		width: 300upx;
		height: 300upx;
		background-color: #dcdcdc;
		opacity: 0.7;
		background-image: url(../../static/scan.png );
		background-repeat: no-repeat;
		border: #007AFF solid 0upx;
		position: relative;
		left: -10%;
		background-size: 100% 100%;
		border-radius: 20%;
		text-align: center;

	}

	.inf {
		position: relative;
		top: 43%;
		color: #000000;
		font-size: 36upx;
	}

	.loginInput {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 54upx;
		margin-right: 54upx;
		margin-top: 90upx;
		z-index: 99;
		position: relative;
		border-radius: 12upx;

	}

	.indexBg {
		/* 		position: fixed;
			top: 0;
			left: 0; */

		width: 100%;
		height: 300upx;
		line-height: 300upx;
		text-align: center;
		background-repeat: no-repeat;
		/*不重复*/
		background-size: 100% 300upx;
		/*满屏*/
		color: #fff;
		font-size: 62upx;
		letter-spacing: 4upx;
		z-index: 99;
		position: relative;
	}

	.loginImg {
		width: 100upx;
		height: 50upx;
		vertical-align: middle;
	}

	.bgc {
		background-color: #fff;
	}

	.search-input {
		width: 100%;
		margin-left: 30upx;
		font-size: 44upx;

	}

	.yan-posi {
		position: absolute;
		right: 0;
		top: 0;
	}

	.font-gray {
		color: #999;
	}

	.text-24 {
		font-size: 24upx;
	}

	.display-inline {
		display: inline-block;
	}

	.margin-t30 {
		margin-top: 20%;
	}

	.loginButton {
		height: 98upx;
		line-height: 98upx;
		background: #65caff;
		box-shadow: 0 2upx 10upx 0 rgba(115, 241, 255, 0.8);
		border-radius: 49upx;
		color: #fff;
		text-align: center;
		z-index: 99;
		position: relative;
	}

	.bottom {
		height: 240upx;
		padding-left: 37%;
	}
</style>
